package com.cat.model.web.action.api;

import java.util.Date;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.cat.model.biz.service.api.UserFavoriteService;
import com.cat.model.common.model.common.UserTokenVO;
import com.cat.model.common.util.ErrorCode;
import com.cat.model.dao.mapper.UserInfoMapper;
import com.cat.model.web.action.base.BaseAction;

public class UserFavoriteAction extends BaseAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = 604080577375901309L;
	
	private String token;
	private Long modelId;
	private Integer page;
	private Integer size;
	
	@Autowired
	private UserInfoMapper userInfoMapper;
	
	@Autowired
	private UserFavoriteService userFavoriteService;
	
	/**
	 * 添加模特新收藏
	 * */
	public void addModelFavorite(){
		if(StringUtils.isEmpty(token)){
			print(ErrorCode.PARAM_ERROR.response());
			return;
		}
		//token过期
		UserTokenVO userToken = userInfoMapper.getUserTokenByToken(token);
		if(null == userToken || userToken.getTokenExpire() < new Date().getTime()){
			print(ErrorCode.TOKEN_EXPIRE.response());
			return;
		}
		
		print(userFavoriteService.addUserModelFavorite(userToken.getUserId(), modelId));
	}
	
	/**
	 * 删除模特收藏
	 * */
	public void delModelFavorite(){
		if(StringUtils.isEmpty(token)){
			print(ErrorCode.PARAM_ERROR.response());
			return;
		}
		//token过期
		UserTokenVO userToken = userInfoMapper.getUserTokenByToken(token);
		if(null == userToken || userToken.getTokenExpire() < new Date().getTime()){
			print(ErrorCode.TOKEN_EXPIRE.response());
			return;
		}
		
		print(userFavoriteService.delUserModelFavorite(userToken.getUserId(), modelId));
	}
	
	/**
	 * 模特收藏列表
	 * */
	public void getModelFavoriteList(){
		if(StringUtils.isEmpty(token)){
			print(ErrorCode.PARAM_ERROR.response());
			return;
		}
		//token过期
		UserTokenVO userToken = userInfoMapper.getUserTokenByToken(token);
		if(null == userToken || userToken.getTokenExpire() < new Date().getTime()){
			print(ErrorCode.TOKEN_EXPIRE.response());
			return;
		}
		
		print(userFavoriteService.getUserModelFavoriteList(userToken.getUserId(), page, size));
	}

	public String getToken() {
		return token;
	}

	public void setToken(String token) {
		this.token = token;
	}

	public Long getModelId() {
		return modelId;
	}

	public void setModelId(Long modelId) {
		this.modelId = modelId;
	}

	public Integer getPage() {
		return page;
	}

	public void setPage(Integer page) {
		this.page = page;
	}

	public Integer getSize() {
		return size;
	}

	public void setSize(Integer size) {
		this.size = size;
	}

}
